home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCfast_malloc.s < prev    next >
Text File  |  1991-08-09  |  3KB  |  140 lines

  1.  
  2. /* A faster version of the standard PCR allocator on SPARCS.  Does not     */
  3. /* handle allocator callbacks.  Does not maintain GC_objects_allocd.       */
  4. /* Instead of fully acquiring the allocation monitor lock, we only         */
  5. /* acquire the associated spin lock.                      */
  6. /* We assume a version of SunOS 4.1 (or later) with the ldstub patch.   */
  7. /* We round the size up to a multiple of 8.  Otherwise no attempt is    */
  8. /* made to merge object sizes.                        */
  9. #    define    ML_LOCK_OFF    0     /* Must be consistent with Threads.h   */
  10. #       define    ML_HOLDER_OFF    8     /* Must be consistent with Threads.h   */
  11. #    define     MAXOBJSZ    2048  /* Must be consistent with GCPrivate.h */
  12.     .global    _GC_words_allocd
  13.     .global _GC_objfreelist
  14.     .global _GC_allocate_ml
  15.     .global _GC_malloc
  16.     
  17.     .global _GC_fast_malloc
  18. _GC_fast_malloc:
  19.     sethi    %hi(_GC_allocate_ml),%o1
  20.     cmp    %o0,MAXOBJSZ
  21.     bg    failed_wo_lock
  22.      or    %o1,%lo(_GC_allocate_ml),%o1
  23.  
  24. !   Attempt to acquire _GC_allocate_ml spin lock
  25.     ldstub    [%o1+ML_LOCK_OFF],%o2
  26.     ld    [%o1+ML_HOLDER_OFF],%o5
  27.     tst    %o2
  28.     bnz    failed_wo_lock
  29.  
  30. !   Round up the size suitably
  31.      add    %o0,7,%o3    ! delay slot OK
  32.     andn    %o3,7,%o3
  33.     
  34. !   Get the free list entry
  35.     sethi    %hi(_GC_objfreelist),%o2
  36.     or    %o2,%lo(_GC_objfreelist),%o2
  37.     ld    [%o3+%o2],%o4
  38.     
  39. !   Is someone in the monitor?
  40.     tst    %o5
  41.     bnz    failed_w_lock
  42.      
  43. !   Was free list nonempty? 
  44.      tst    %o4    !  delay slot OK
  45.     bnz,a    success
  46.      ld    [%o4],%o5
  47.      
  48. failed_w_lock:
  49.     set    _GC_malloc,%o2
  50.     jmp    %o2
  51.      st    %g0,[%o1+ML_LOCK_OFF]
  52.      
  53. failed_wo_lock:
  54.     set    _GC_malloc,%o2
  55.     jmp    %o2
  56.      nop
  57.      
  58. success:
  59. !   Update the free list entry
  60.     not     %o5,%o5
  61.     st    %o5,[%o2+%o3]
  62. !   Update GC_words_allocd and clear the link field in the object
  63.     sethi    %hi(_GC_words_allocd),%o2
  64.     ld    [%o2+%lo(_GC_words_allocd)],%o5
  65.     st    %g0,[%o4]
  66.     sra    %o3,2,%o3
  67.     add    %o5,%o3,%o5
  68.     st    %o5,[%o2+%lo(_GC_words_allocd)]
  69.     
  70.  
  71. !   return (%o4)
  72.     mov    %o4,%o0
  73.     retl
  74. !   Release spin lock
  75.      st    %g0,[%o1+ML_LOCK_OFF]    ! delay slot
  76.     
  77.     
  78.     .global _GC_aobjfreelist
  79.     .global _GC_malloc_atomic
  80.     
  81.     .global _GC_fast_malloc_atomic
  82. _GC_fast_malloc_atomic:
  83.     sethi    %hi(_GC_allocate_ml),%o1
  84.     cmp    %o0,MAXOBJSZ
  85.     bg    atomic_failed_wo_lock
  86.      or    %o1,%lo(_GC_allocate_ml),%o1
  87.  
  88. !   Attempt to acquire _GC_allocate_ml spin lock
  89.     ldstub    [%o1+ML_LOCK_OFF],%o2
  90.     ld    [%o1+ML_HOLDER_OFF],%o5
  91.     tst    %o2
  92.     bnz    atomic_failed_wo_lock
  93.  
  94. !   Round up the size suitably
  95.      add    %o0,7,%o3    ! delay slot OK
  96.     andn    %o3,7,%o3
  97.     
  98. !   Get the free list entry
  99.     sethi    %hi(_GC_aobjfreelist),%o2
  100.     or    %o2,%lo(_GC_aobjfreelist),%o2
  101.     ld    [%o3+%o2],%o4
  102.     
  103. !   Is someone in the monitor?
  104.     tst    %o5
  105.     bnz    atomic_failed_w_lock
  106.      
  107. !   Was free list nonempty? 
  108.      tst    %o4    !  delay slot OK
  109.     bnz,a    atomic_success
  110.      ld    [%o4],%o5
  111.      
  112. atomic_failed_w_lock:
  113.     set    _GC_malloc_atomic,%o2
  114.     jmp    %o2
  115.      st    %g0,[%o1+ML_LOCK_OFF]
  116.      
  117. atomic_failed_wo_lock:
  118.     set    _GC_malloc_atomic,%o2
  119.     jmp    %o2
  120.      nop
  121.      
  122. atomic_success:
  123. !   Update the free list entry
  124.     not    %o5,%o5
  125.     st    %o5,[%o2+%o3]
  126. !   Update GC_words_allocd and clear the link field in the object
  127.     sethi    %hi(_GC_words_allocd),%o2
  128.     ld    [%o2+%lo(_GC_words_allocd)],%o5
  129.     st    %g0,[%o4]
  130.     sra    %o3,2,%o3
  131.     add    %o5,%o3,%o5
  132.     st    %o5,[%o2+%lo(_GC_words_allocd)]
  133.     
  134.  
  135. !   return (%o4)
  136.     mov    %o4,%o0
  137.     retl
  138. !   Release spin lock
  139.      st    %g0,[%o1+ML_LOCK_OFF]    ! delay slot
  140.